
export default {
    install(Vue) {
        let Te = function () {
            this.v = '20210315';
            //大屏自适应样式集合
            this.adapStyle = {};
            //三维引擎对象
            this.webGis = null;
            //定时器集合
            this.interval = {}
        };

        Te.fn = Te.prototype;
        let _conf = window.conf;

        Te.fn.selfAdaption = function () {
            let _w = window.screen.width,
                _h = window.screen.height,
                _stylyObj = {};


            _stylyObj.nav = {
                'transform': 'scale(' + _w / _conf.width + ',' + _h / _conf.height + ')',
                'width': _conf.width + 'px',
                'height': _conf.top + 'px'
            }

            _stylyObj.nmodule = {
                'transform': 'scale(' + _w / _conf.width + ',' + _h / _conf.height + ')',
                'transformOrigin': '0 0'
            }

            _stylyObj.subjects = {
                'transform': 'scale(' + _w / _conf.width + ',' + _h / _conf.height + ')',
                'top': _conf.top + 20 + 'px'
            }

            _stylyObj.left = {
                'transform': 'scale(' + _w / _conf.width + ',' + _h / _conf.height + ')',
                'width': _conf.prop[0] + 'px',
                'height': _conf.height + 'px',
                'padding-top': _conf.top + 'px',
                'transformOrigin': '0 0'
            }

            _stylyObj.right = {
                'transform': 'scale(' + _w / _conf.width + ',' + _h / _conf.height + ')',
                'width': _conf.prop[1] + 'px',
                'height': _conf.height + 'px',
                'padding-top': _conf.top + 'px',
                'transformOrigin': _conf.prop[1] + 'px 0'
            }

            _stylyObj.ue = {
                'width': _conf.width + 'px',
                'height': _conf.height + 'px'
            }

            _conf.multscreen = _w / _conf.width;

            this.adapStyle = _stylyObj

        }

        Te.fn.gisBJinit = function (obj, cb) {
            let me = this;
            GeoworldLib.createInstance(obj.container, { sdkType: "release", configLink: obj.configLink, gisserver: obj.gisserver }, function (e) {
                me.webGis = e;
                if (cb && typeof cb === 'function') {
                    cb()
                }
            });
        }

        Te.fn.gisHFinit = function (obj) {
            this.webGis = new SmartEarth.SGWorld(obj.container, obj.cesium, obj.image, obj.position, function () {
            });
        }

        /**
    * 获取当前日期前多少天的日期
    * @n 天数
    * @ymd 日期 //格式 2021-01-01
    */
        Te.fn.getBeforeDate = function (n, ymd) {
            var n = n,
                year = 0,
                mon = 0,
                day = 0,
                d = new Date();
            if (ymd) {
                var time = new Date(ymd).getTime() - n * 86400000;
                d.setTime(time);

            } else {
                year = d.getFullYear();
                mon = d.getMonth() + 1;
                day = d.getDate();
                if (day <= n) {
                    if (mon > 1) {
                        mon = mon - 1;
                    }
                    else {
                        year = year - 1;
                        mon = 12;
                    }
                }
                d.setDate(d.getDate() - n);
            }
            year = d.getFullYear();
            mon = d.getMonth() + 1;
            day = d.getDate();
            return year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
        }

        /**
   * 获取当前日期后多少天的日期
   * @n 天数
   * @ymd 日期 //格式 2021-01-01
   */
        Te.fn.getAfterDate = function (n, ymd) {
            var n = n,
                year = 0,
                mon = 0,
                day = 0,
                d = new Date();
            if (ymd) {
                var time = new Date(ymd).getTime() + n * 86400000;
                d.setTime(time);

            } else {
                year = d.getFullYear();
                mon = d.getMonth() + 1;
                day = d.getDate();
                if (day <= n) {
                    if (mon > 1) {
                        mon = mon - 1;
                    }
                    else {
                        year = year - 1;
                        mon = 12;
                    }
                }
                d.setDate(d.getDate() + n);
            }
            year = d.getFullYear();
            mon = d.getMonth() + 1;
            day = d.getDate();
            return year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
        }

        /**
   * 毫秒数转换为日期格式
   * 
   * @d 毫秒数
   */
        Te.fn.date2String_OnlyDate = function (d) {
            var date = new Date(d);
            var seperator1 = "-";
            var seperator2 = ":";
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = year + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

        let Tebs = Vue.prototype.Tebs = new Te();

        Tebs.selfAdaption();

    }
}